using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using BodySoundSimulator.CaseData;
using BodySoundSimulator.AbsoluteMapData;

namespace BodySoundSimulator.Recording
{
	public partial class FrontViewSoundMapEffectsEditor : UserControl
	{
		#region Filelds
		ISoundMapEditorServices soundMapEditorServices;
		#endregion

		#region Constructors
		public FrontViewSoundMapEffectsEditor(ISoundMapEditorServices soundMapEditorServices)
		{
			InitializeComponent();
			this.soundMapEditorServices = soundMapEditorServices;
			UpdateTrackBarTags();
			UpdateUI();
		}
		#endregion

		#region Private methods

		private void UpdateUI()
		{
			if (this.soundMapEditorServices.View == PatientView.FrontView)
			{
				TrackBar[] trackBars = new TrackBar[] 
				{ 
					this.trkBarHeartSoundOne, this.trkBarHeartSoundTwo, this.trkBarHeartSoundThree,
					this.trkBarHeartSoundFour, this.trkBarHeartSoundFive,
					this.trkBarLungSoundOne, this.trkBarLungSoundTwo, this.trkBarLungSoundThree,
					this.trkBarLungSoundFour, this.trkBarLungSoundFive
				};
				foreach (TrackBar trackBar in trackBars)
				{
					float effectValue = this.soundMapEditorServices.SelectedFrontViewCellContributionData.FrontViewEffects[(int)((FrontViewCommonAuscultationSiteType)trackBar.Tag)].Effect;
					trackBar.Value = (int)Math.Round((effectValue * 10.0f));
				}
			}
		}

		private void UpdateTrackBarTags()
		{
			this.trkBarHeartSoundOne.Tag = FrontViewCommonAuscultationSiteType.heartSoundSiteOne;
			this.trkBarHeartSoundTwo.Tag = FrontViewCommonAuscultationSiteType.heartSoundSiteTwo;
			this.trkBarHeartSoundThree.Tag = FrontViewCommonAuscultationSiteType.heartSoundSiteThree;
			this.trkBarHeartSoundFour.Tag = FrontViewCommonAuscultationSiteType.heartSoundSiteFour;
			this.trkBarHeartSoundFive.Tag = FrontViewCommonAuscultationSiteType.heartSoundSiteFive;

			this.trkBarLungSoundOne.Tag = FrontViewCommonAuscultationSiteType.lungSoundSiteOne;
			this.trkBarLungSoundTwo.Tag = FrontViewCommonAuscultationSiteType.lungSoundSiteTwo;
			this.trkBarLungSoundThree.Tag = FrontViewCommonAuscultationSiteType.lungSoundSiteThree;
			this.trkBarLungSoundFour.Tag = FrontViewCommonAuscultationSiteType.lungSoundSiteFour;
			this.trkBarLungSoundFive.Tag = FrontViewCommonAuscultationSiteType.lungSoundSiteFive;
		}
		#endregion

		#region UI event handlers

		private void AllTrackBars_Scroll(object sender, EventArgs e)
		{
			TrackBar trackBar = sender as TrackBar;
			this.soundMapEditorServices.UpdateFrontViewEffect((FrontViewCommonAuscultationSiteType)trackBar.Tag,
				(float)trackBar.Value / 10);
		}

		#endregion
	}
}
